package com.atguigu.tingshu.order.api;

import com.atguigu.tingshu.common.login.annotation.TingShuLogin;
import com.atguigu.tingshu.common.result.Result;
import com.atguigu.tingshu.order.service.OrderInfoService;
import com.atguigu.tingshu.vo.order.OrderInfoVo;
import com.atguigu.tingshu.vo.order.TradeVo;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.CollectionUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Tag(name = "订单管理")
@RestController
@RequestMapping("api/order/orderInfo")
@SuppressWarnings({"unchecked", "rawtypes"})
public class OrderInfoApiController {

	@Autowired
	private OrderInfoService orderInfoService;
//Request URL: http://localhost:8500/api/order/orderInfo/trade
	@PostMapping("/trade")
	@Operation(summary = "订单结算页处理")
	@TingShuLogin
	public Result trade(@RequestBody TradeVo tradeVo){
		OrderInfoVo orderInfoVo = orderInfoService.trade(tradeVo);
		List<Object> exitItemIds = orderInfoVo.getExitItemIds();
		if (!CollectionUtils.isEmpty(exitItemIds)){
			return Result.build(exitItemIds,301,"付款项已经存在");
		}
		return Result.ok(orderInfoVo);
	}
	//Request URL: http://localhost:8500/api/order/orderInfo/submitOrder
	@PostMapping ("/submitOrder")
	@Operation(summary = "提交订单")
	@TingShuLogin
	public Result submitOrder(@RequestBody OrderInfoVo orderInfoVo){
		Map<String, Object> map = orderInfoService.submitOrder(orderInfoVo);
		return Result.ok(map);
	}
}

